package com.cskaoyan.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author stone
 * @date 2022/05/03 16:36
 */
@Component
public class CustomHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse, Object o, Exception e) {
        System.out.println("exception:" + e.getMessage());
        /*try {
            httpServletResponse.getWriter().append("发生异常了");
        } catch (IOException ioException) {
            ioException.printStackTrace();
        }*/
        if (e instanceof ArithmeticException) {

        }
        return new ModelAndView("/exception.jsp");
    }
}
